import config from '@/config'
import store from '@/store'
import RequestBase from '@/utils/request.js'

const baseRequest = new RequestBase(config.education)

// 获取在线考试列表
export function list({
	examName = '',
	pageSize = 10,
	pageNum = 1
} = {}) {
	return baseRequest.get(`/online-exam/list`, {
		examName,
		pageSize,
		pageNum
	})
}

// 开始考试
export function reqGetStart(examPlanId) {
	return baseRequest.get(`/online-exam/start/${examPlanId}`)
}

// 获取试卷题目
export function reqGetById(examPlanId) {
	return baseRequest.get(`/online-exam/${examPlanId}`)
}

// 提交试卷题目
export function reqPostSubmit(data) {
	return baseRequest.post(`/online-exam`, data)
}

// 提交试卷题目
export function reqGetReesult(examPlanId) {
	return baseRequest.get(`/online-exam/score/${examPlanId}`)
}

// 获取试卷题目
export function reqGetDetail(examPlanId) {
	return baseRequest.get(`/exam-record/detail?examPlanId=${examPlanId}`)
}

//考试记录
export function recordList({
	examName,
	examPlanId,
	exerciseType,
	pageSize = 10,
	pageNum = 1
} = {}) {
	return baseRequest.get('/exam-record/list', {
		examName,
		examPlanId,
		exerciseType,
		personId: store.getters.staffId,
		pageSize,
		pageNum
	})
}


// 模拟考试记录
export function mockTestRecordList() {
	return baseRequest.get('/simulation-exam-record/list')
}

// 模拟考试记录详情
export function mockTestRecordDetail(simulationId) {
	return baseRequest.get('/simulation-exam-record/' + simulationId, )
}

// 考试题目
export function getTestQuestions(taskId) {
	return baseRequest.get(`/plan/exam-task/${taskId}`)
}

// 线下考试列表
export function getTodoTestList(query) {
	return baseRequest.get('/plan/exam-task/todo-list', query)
}

// 考试记录列表
export function getTestList(query) {
	return baseRequest.get("/plan/exam-task/submit-list", query);
  }

// 开始考试
export function getStartTest(taskId) {
	return baseRequest.put(`/plan/exam-task/${taskId}/start`)
}

// 提交一个题目
export function submitOneExam(taskId, data) {
	return baseRequest.put(`/plan/exam-task/${taskId}/submit-question-single`, data)
}

//  提交考试
export function submitEaxm(taskId) {
	return baseRequest.put(`/plan/exam-task/${taskId}/submit-exam`)
}

// 获取考试次数
export function reqUserExamCount(planId) {
	return baseRequest.get(`/plan/online-exam/${planId}/user-exam-count`);
}

// 通过考试计划id创建考试
export function reqCreateExam(planId) {
	return baseRequest.put(`/plan/online-exam/${planId}/task`)
}
